package com.ruoyi.kanban.controller;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kanban.domain.SupplyFrameworkItem;
import com.ruoyi.kanban.service.ISupplyFrameworkItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货框架物料明细Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/kanban/supplyFrameworkItem")
public class SupplyFrameworkItemController extends BaseController
{
    @Autowired
    private ISupplyFrameworkItemService supplyFrameworkItemService;

    /**
     * 查询供货框架物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplyFrameworkItem supplyFrameworkItem)
    {
        startPage();
        List<SupplyFrameworkItem> list = supplyFrameworkItemService.selectSupplyFrameworkItemList(supplyFrameworkItem);
        return getDataTable(list);
    }

    /**
     * 根据框架协议ID查询物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:list')")
    @GetMapping("/listByFrameworkId/{frameworkId}")
    public AjaxResult listByFrameworkId(@PathVariable("frameworkId") Long frameworkId)
    {
        List<SupplyFrameworkItem> list = supplyFrameworkItemService.selectSupplyFrameworkItemByFrameworkId(frameworkId);
        return AjaxResult.success(list);
    }

    /**
     * 导出供货框架物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:export')")
    @Log(title = "供货框架物料明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplyFrameworkItem supplyFrameworkItem)
    {
        List<SupplyFrameworkItem> list = supplyFrameworkItemService.selectSupplyFrameworkItemList(supplyFrameworkItem);
        ExcelUtil<SupplyFrameworkItem> util = new ExcelUtil<SupplyFrameworkItem>(SupplyFrameworkItem.class);
        util.exportExcel(response, list, "供货框架物料明细数据");
    }

    /**
     * 获取供货框架物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(supplyFrameworkItemService.selectSupplyFrameworkItemById(id));
    }

    /**
     * 新增供货框架物料明细
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:add')")
    @Log(title = "供货框架物料明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplyFrameworkItem supplyFrameworkItem)
    {
        return toAjax(supplyFrameworkItemService.insertSupplyFrameworkItem(supplyFrameworkItem));
    }

    /**
     * 修改供货框架物料明细
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:edit')")
    @Log(title = "供货框架物料明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplyFrameworkItem supplyFrameworkItem)
    {
        return toAjax(supplyFrameworkItemService.updateSupplyFrameworkItem(supplyFrameworkItem));
    }

    /**
     * 删除供货框架物料明细
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:remove')")
    @Log(title = "供货框架物料明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supplyFrameworkItemService.deleteSupplyFrameworkItemByIds(Arrays.stream(ids).collect(Collectors.toList())));
    }

    /**
     * 根据框架协议ID删除物料明细
     */
    @PreAuthorize("@ss.hasPermi('kanban:frameworkItem:remove')")
    @Log(title = "供货框架物料明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByFrameworkId/{frameworkId}")
    public AjaxResult removeByFrameworkId(@PathVariable("frameworkId") Long frameworkId)
    {
        return toAjax(supplyFrameworkItemService.deleteSupplyFrameworkItemByFrameworkId(frameworkId));
    }
}